<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>虚拟机资源计算器</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }

        .header {
            text-align: center;
            margin-bottom: 30px;
        }

        .header h1 {
            color: #2c3e50;
            font-size: 2.5em;
            margin-bottom: 10px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
        }

        .header p {
            color: #7f8c8d;
            font-size: 1.1em;
        }

        .calculator-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 30px;
            margin-bottom: 30px;
        }

        .input-section {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            border-radius: 15px;
            padding: 25px;
            color: white;
        }

        .result-section {
            background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
            border-radius: 15px;
            padding: 25px;
            color: white;
        }

        .section-title {
            font-size: 1.3em;
            font-weight: bold;
            margin-bottom: 20px;
            text-align: center;
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
        }

        .config-item {
            background: rgba(255, 255, 255, 0.2);
            border-radius: 10px;
            padding: 15px;
            margin-bottom: 15px;
            backdrop-filter: blur(5px);
        }

        .config-item h3 {
            margin-bottom: 10px;
            font-size: 1.1em;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .config-controls {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 15px;
        }

        .config-controls button {
            background: rgba(255, 255, 255, 0.3);
            border: none;
            color: white;
            padding: 5px 10px;
            border-radius: 5px;
            cursor: pointer;
            font-weight: bold;
            transition: all 0.3s;
        }

        .config-controls button:hover {
            background: rgba(255, 255, 255, 0.5);
            transform: scale(1.05);
        }

        .config-controls input {
            width: 60px;
            text-align: center;
            border: none;
            border-radius: 5px;
            padding: 5px;
            font-weight: bold;
        }

        .spec-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 10px;
            margin-bottom: 10px;
        }

        .spec-item {
            background: rgba(255, 255, 255, 0.15);
            padding: 8px;
            border-radius: 5px;
            font-size: 0.9em;
        }

        .spec-item label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            font-size: 0.85em;
        }

        .spec-item input, .spec-item select {
            width: 100%;
            border: none;
            border-radius: 3px;
            padding: 4px;
            text-align: center;
            font-size: 0.9em;
        }

        .disk-config {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 8px;
            padding: 10px;
            margin-bottom: 10px;
        }

        .disk-title {
            font-size: 0.9em;
            font-weight: bold;
            margin-bottom: 8px;
            text-align: center;
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .disk-row {
            display: grid;
            grid-template-columns: 1fr 1fr 1fr auto;
            gap: 8px;
            align-items: end;
            margin-bottom: 8px;
        }

        .auto-adjust {
            font-size: 0.7em;
            opacity: 0.8;
            margin-top: 2px;
        }

        .data-disks-container {
            max-height: 200px;
            overflow-y: auto;
        }

        .data-disk-item {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 6px;
            padding: 8px;
            margin-bottom: 6px;
            border-left: 3px solid rgba(255, 255, 255, 0.3);
        }

        .add-disk-btn {
            background: rgba(255, 255, 255, 0.2);
            border: none;
            color: white;
            padding: 8px 12px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 0.8em;
            transition: all 0.3s;
        }

        .add-disk-btn:hover {
            background: rgba(255, 255, 255, 0.3);
        }

        .remove-disk-btn {
            background: #e74c3c;
            border: none;
            color: white;
            padding: 4px 8px;
            border-radius: 3px;
            cursor: pointer;
            font-size: 0.7em;
        }

        .remove-disk-btn:hover {
            background: #c0392b;
        }

        .result-item {
            background: rgba(255, 255, 255, 0.2);
            border-radius: 10px;
            padding: 15px;
            margin-bottom: 15px;
            backdrop-filter: blur(5px);
        }

        .result-item h3 {
            margin-bottom: 10px;
            font-size: 1.1em;
            text-align: center;
        }

        .result-stats {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
            gap: 8px;
        }

        .stat-box {
            background: rgba(255, 255, 255, 0.2);
            padding: 8px;
            border-radius: 6px;
            text-align: center;
        }

        .stat-label {
            font-size: 0.75em;
            opacity: 0.8;
            margin-bottom: 3px;
        }

        .stat-value {
            font-size: 1em;
            font-weight: bold;
        }

        .total-summary {
            background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
            border-radius: 15px;
            padding: 25px;
            margin-top: 20px;
            color: #2c3e50;
        }

        .total-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
            gap: 15px;
        }

        .total-item {
            background: rgba(255, 255, 255, 0.8);
            padding: 15px;
            border-radius: 10px;
            text-align: center;
            transition: transform 0.3s;
        }

        .total-item:hover {
            transform: translateY(-5px);
        }

        .total-item .label {
            font-size: 0.9em;
            color: #7f8c8d;
            margin-bottom: 5px;
        }

        .total-item .value {
            font-size: 1.5em;
            font-weight: bold;
            color: #2c3e50;
        }

        .add-config-btn {
            background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
            border: none;
            color: #2c3e50;
            padding: 15px 30px;
            border-radius: 10px;
            font-size: 1.1em;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s;
            width: 100%;
            margin-top: 10px;
        }

        .add-config-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        }

        .delete-btn {
            background: #e74c3c;
            border: none;
            color: white;
            padding: 5px 10px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 0.8em;
            margin-left: 10px;
        }

        .delete-btn:hover {
            background: #c0392b;
        }

        .disk-type-stats {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 8px;
            padding: 10px;
            margin-top: 10px;
        }

        .disk-stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
            gap: 5px;
        }

        .disk-stat-item {
            text-align: center;
            font-size: 0.8em;
        }

        .disk-stat-label {
            opacity: 0.8;
            margin-bottom: 2px;
        }

        .disk-stat-value {
            font-weight: bold;
        }

        .disk-summary {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 6px;
            padding: 8px;
            margin-top: 8px;
            font-size: 0.85em;
        }

        .disk-summary-row {
            display: flex;
            justify-content: space-between;
            margin-bottom: 3px;
        }

        .empty-state {
            text-align: center;
            padding: 40px 20px;
            color: rgba(255, 255, 255, 0.8);
        }

        .empty-state h3 {
            font-size: 1.2em;
            margin-bottom: 10px;
        }

        .empty-state p {
            font-size: 0.9em;
            opacity: 0.7;
        }

        @media (max-width: 768px) {
            .calculator-grid {
                grid-template-columns: 1fr;
            }
            
            .spec-grid {
                grid-template-columns: 1fr;
            }
            
            .total-grid {
                grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
            }

            .disk-row {
                grid-template-columns: 1fr 1fr auto;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>🖥️ 虚拟机资源计算器</h1>
            <p>快速计算虚拟机集群的资源配置需求 - 支持多块数据盘配置</p>
        </div>

        <div class="calculator-grid">
            <div class="input-section">
                <div class="section-title">📋 配置管理</div>
                
                <!-- 文字识别功能 -->
                <div style="background: rgba(255, 255, 255, 0.2); border-radius: 10px; padding: 15px; margin-bottom: 20px; backdrop-filter: blur(5px);">
                    <h3 style="margin-bottom: 10px; font-size: 1em;">🔍 智能批量识别配置</h3>
                    <textarea id="configText" placeholder="支持批量输入多个配置，每行一个配置，例如：&#10;4台虚机，操作系统：麒麟，64C 128G，1000G系统盘+80T数据盘，都分配校园网IP，20g带宽。虚机命名：后端服务器MS01-后端服务器MS04&#10;7台虚机，操作系统：麒麟，32C64G，1000G系统盘+2000G数据盘，都分配校园网IP，20g带宽。虚机命名：前端服务器webadmin" 
                              style="width: 100%; height: 120px; border: none; border-radius: 5px; padding: 8px; resize: vertical; font-size: 0.9em;"></textarea>
                    <div style="display: flex; gap: 10px; margin-top: 8px;">
                        <button onclick="parseConfigText()" style="background: rgba(255, 255, 255, 0.3); border: none; color: white; padding: 8px 15px; border-radius: 5px; cursor: pointer; font-size: 0.9em; transition: all 0.3s;" 
                                onmouseover="this.style.background='rgba(255, 255, 255, 0.5)'" onmouseout="this.style.background='rgba(255, 255, 255, 0.3)'">
                            🚀 批量解析并添加
                        </button>
                        <button onclick="clearConfigText()" style="background: rgba(255, 255, 255, 0.2); border: none; color: white; padding: 8px 15px; border-radius: 5px; cursor: pointer; font-size: 0.9em; transition: all 0.3s;" 
                                onmouseover="this.style.background='rgba(255, 255, 255, 0.4)'" onmouseout="this.style.background='rgba(255, 255, 255, 0.2)'">
                            🗑️ 清空
                        </button>
                    </div>
                </div>
                
                <div id="configurations">
                    <div class="empty-state">
                        <h3>暂无配置</h3>
                        <p>点击下方按钮添加您的虚拟机配置</p>
                    </div>
                </div>
                <button class="add-config-btn" onclick="addConfiguration()">
                    ➕ 添加新配置
                </button>
            </div>

            <div class="result-section">
                <div class="section-title">📊 分组统计</div>
                <div id="groupResults">
                    <div class="empty-state">
                        <h3>暂无统计数据</h3>
                        <p>添加配置后这里会显示详细统计</p>
                    </div>
                </div>
            </div>
        </div>

        <div class="total-summary">
            <div class="section-title">📈 总计资源</div>
            <div class="total-grid">
                <div class="total-item">
                    <div class="label">虚拟机总数</div>
                    <div class="value" id="totalVMs">0</div>
                </div>
                <div class="total-item">
                    <div class="label">CPU核心数</div>
                    <div class="value" id="totalCPU">0</div>
                </div>
                <div class="total-item">
                    <div class="label">内存容量</div>
                    <div class="value" id="totalMemory">0G</div>
                </div>
                <div class="total-item">
                    <div class="label">Dell系统盘</div>
                    <div class="value" id="totalSystemDiskDell">0G</div>
                </div>
                <div class="total-item">
                    <div class="label">SSD系统盘</div>
                    <div class="value" id="totalSystemDiskSSD">0G</div>
                </div>
                <div class="total-item">
                    <div class="label">Dell数据盘</div>
                    <div class="value" id="totalDataDiskDell">0G</div>
                </div>
                <div class="total-item">
                    <div class="label">曙光数据盘</div>
                    <div class="value" id="totalDataDiskShuguang">0G</div>
                </div>
                <div class="total-item">
                    <div class="label">SSD数据盘</div>
                    <div class="value" id="totalDataDiskSSD">0G</div>
                </div>
                <div class="total-item">
                    <div class="label">校园网IP</div>
                    <div class="value" id="totalIPs">0</div>
                </div>
                <div class="total-item">
                    <div class="label">总带宽</div>
                    <div class="value" id="totalBandwidth">0M</div>
                </div>
            </div>
        </div>
    </div>

    <script>
        let configCount = 0;
        let configurations = [];
        let dataDiskCount = 0;

        // 磁盘类型定义
        const DISK_TYPES = {
            system: {
                dell: { name: 'Dell盘', needsAdjust: true },
                ssd: { name: 'SSD盘', needsAdjust: false }
            },
            data: {
                dell: { name: 'Dell盘', needsAdjust: true },
                shuguang: { name: '曙光盘', needsAdjust: false },
                ssd: { name: 'SSD盘', needsAdjust: false }
            }
        };

        // 自动调整到8的倍数
        function adjustToMultipleOf8(value) {
            return Math.ceil(value / 8) * 8;
        }

        // 清空配置文本
        function clearConfigText() {
            document.getElementById('configText').value = '';
        }

        // 解析配置文字 - 支持批量
        function parseConfigText() {
            const text = document.getElementById('configText').value.trim();
            if (!text) {
                alert('请输入配置描述');
                return;
            }

            try {
                // 按行分割，过滤空行
                const lines = text.split('\n').filter(line => line.trim().length > 0);
                let successCount = 0;
                let failCount = 0;

                lines.forEach((line, index) => {
                    try {
                        const config = extractConfigFromText(line.trim());
                        if (config) {
                            // 添加解析出的配置
                            configCount++;
                            config.id = configCount;
                            // 如果有虚机命名，使用命名，否则使用默认名称
                            config.name = config.customName || `智能识别${configCount}`;
                            configurations.push(config);
                            successCount++;
                        } else {
                            console.warn(`第${index + 1}行解析失败: ${line}`);
                            failCount++;
                        }
                    } catch (error) {
                        console.error(`第${index + 1}行解析出错: ${error.message}`);
                        failCount++;
                    }
                });

                renderConfigurations();
                calculateTotals();
                
                // 显示解析结果
                if (successCount > 0) {
                    let message = `成功解析 ${successCount} 个配置`;
                    if (failCount > 0) {
                        message += `，${failCount} 个配置解析失败`;
                    }
                    alert(message);
                    
                    // 清空输入框
                    document.getElementById('configText').value = '';
                } else {
                    alert('无法解析任何配置信息，请检查输入格式');
                }
            } catch (error) {
                alert('解析出错：' + error.message);
            }
        }

        // 从文字中提取配置信息 - 修正版
        function extractConfigFromText(text) {
            console.log('开始解析文本:', text);
            
            const config = {
                vmCount: 1,
                cpuPerVM: 4,
                memoryPerVM: 8,
                systemDiskPerVM: 100,
                systemDiskType: 'dell',
                dataDisks: [],
                bandwidth: 20,
                customName: null
            };

            // 提取虚机数量
            const vmMatch = text.match(/(\d+)台虚机/);
            if (vmMatch) {
                config.vmCount = parseInt(vmMatch[1]);
                console.log('解析到虚机数量:', config.vmCount);
            }

            // 提取CPU (支持多种格式)
            const cpuMatch = text.match(/(\d+)C/) || text.match(/(\d+)核/);
            if (cpuMatch) {
                config.cpuPerVM = parseInt(cpuMatch[1]);
                console.log('解析到CPU:', config.cpuPerVM);
            }

            // 提取内存 (更灵活的匹配)
            let memoryMatch = text.match(/(\d+)C\s*(\d+)G/) || // 64C 128G格式
                             text.match(/(\d+)C(\d+)G/) ||     // 64C128G格式
                             text.match(/(\d+)核\s*(\d+)G/) || // 64核 128G格式
                             text.match(/(\d+)G(?=.*内存)/);   // XG内存格式
            
            if (memoryMatch) {
                const memValue = memoryMatch[2] || memoryMatch[1];
                config.memoryPerVM = parseInt(memValue);
                console.log('解析到内存:', config.memoryPerVM);
            }

            // 提取系统盘
            const systemDiskMatch = text.match(/(\d+)G系统盘/);
            if (systemDiskMatch) {
                config.systemDiskPerVM = parseInt(systemDiskMatch[1]);
                console.log('解析到系统盘:', config.systemDiskPerVM);
            }

            // 提取数据盘 - 重点修复
            if (text.includes('数据盘')) {
                console.log('发现数据盘配置');
                const diskPattern = /(\d+(?:\.\d+)?)[TG]数据盘/g;
                let match;
                
                while ((match = diskPattern.exec(text)) !== null) {
                    let size = parseFloat(match[1]);
                    const isT = match[0].includes('T');
                    
                    console.log('找到数据盘:', size, isT ? 'T' : 'G');
                    
                    // T转G
                    if (isT) {
                        size = size * 1000;
                    }
                    
                    const finalSize = Math.round(size);
                    console.log('最终数据盘大小:', finalSize + 'G');
                    
                    // 根据大小选择磁盘类型：≥1000G选择曙光盘
                    let diskType;
                    if (finalSize >= 1000) {
                        diskType = 'shuguang';
                        console.log('选择曙光盘 (≥1000G)');
                    } else {
                        diskType = 'dell';
                        console.log('选择Dell盘 (<1000G)');
                    }
                    
                    config.dataDisks.push({
                        id: ++dataDiskCount,
                        size: finalSize,
                        type: diskType
                    });
                }
            }

            // 提取带宽 - 重点修复
            if (text.includes('带宽')) {
                console.log('发现带宽配置');
                const bwPattern = /(\d+(?:\.\d+)?)[gGM]带宽/;
                const bwMatch = text.match(bwPattern);
                
                if (bwMatch) {
                    let bandwidth = parseFloat(bwMatch[1]);
                    const matchText = bwMatch[0];
                    
                    console.log('找到带宽:', bandwidth, matchText);
                    
                    // g和G都转换为M (×1000)
                    if (matchText.includes('g') || matchText.includes('G')) {
                        bandwidth = bandwidth * 1000;
                        console.log('转换后带宽:', bandwidth + 'M');
                    }
                    
                    config.bandwidth = Math.round(bandwidth);
                }
            }

            // 提取虚机命名
            const namingPatterns = [
                /虚机命名[：:]\s*["""]([^"""]+)["""]/, 
                /虚机命名[：:]\s*([^，。]+?)(?=[，。]|$)/, 
                /命名[：:]\s*["""]([^"""]+)["""]/, 
                /命名[：:]\s*([^，。]+?)(?=[，。]|$)/ 
            ];

            for (const pattern of namingPatterns) {
                const nameMatch = text.match(pattern);
                if (nameMatch) {
                    config.customName = nameMatch[1].trim();
                    console.log('解析到名称:', config.customName);
                    break;
                }
            }

            console.log('最终配置:', config);

            // 验证是否解析到了基本信息
            if (config.vmCount > 0 && (config.cpuPerVM > 0 || config.memoryPerVM > 0)) {
                return config;
            }

            return null;
        }

        function addConfiguration() {
            configCount++;
            const config = {
                id: configCount,
                name: `配置${configCount}`,
                vmCount: 1,
                cpuPerVM: 4,
                memoryPerVM: 8,
                systemDiskPerVM: 100,
                systemDiskType: 'dell',
                dataDisks: [], // 默认没有数据盘
                bandwidth: 20
            };
            configurations.push(config);
            renderConfigurations();
            calculateTotals();
        }

        function removeConfiguration(id) {
            configurations = configurations.filter(config => config.id !== id);
            renderConfigurations();
            calculateTotals();
        }

        function updateConfiguration(id, field, value) {
            const config = configurations.find(c => c.id === id);
            if (config) {
                if (field === 'systemDiskPerVM') {
                    config[field] = parseInt(value) || 0;
                } else if (field === 'systemDiskType') {
                    config[field] = value;
                } else {
                    config[field] = parseInt(value) || 0;
                }
                renderConfigurations();
                calculateTotals();
            }
        }

        function addDataDisk(configId) {
            const config = configurations.find(c => c.id === configId);
            if (config) {
                config.dataDisks.push({
                    id: ++dataDiskCount,
                    size: 500,
                    type: 'dell'
                });
                renderConfigurations();
                calculateTotals();
            }
        }

        function removeDataDisk(configId, diskId) {
            const config = configurations.find(c => c.id === configId);
            if (config) {
                config.dataDisks = config.dataDisks.filter(disk => disk.id !== diskId);
                renderConfigurations();
                calculateTotals();
            }
        }

        function updateDataDisk(configId, diskId, field, value) {
            const config = configurations.find(c => c.id === configId);
            if (config) {
                const disk = config.dataDisks.find(d => d.id === diskId);
                if (disk) {
                    if (field === 'size') {
                        const newSize = parseInt(value) || 0;
                        disk.size = newSize;
                        // 根据大小自动选择磁盘类型
                        if (newSize >= 1000) {
                            disk.type = 'shuguang';
                        } else {
                            disk.type = 'dell';
                        }
                    } else {
                        disk[field] = value;
                    }
                    renderConfigurations();
                    calculateTotals();
                }
            }
        }

        function changeVMCount(id, change) {
            const config = configurations.find(c => c.id === id);
            if (config) {
                config.vmCount = Math.max(1, config.vmCount + change);
                renderConfigurations();
                calculateTotals();
            }
        }

        function getAdjustedDiskSize(size, type, diskCategory) {
            const diskTypeInfo = DISK_TYPES[diskCategory][type];
            return diskTypeInfo.needsAdjust ? adjustToMultipleOf8(size) : size;
        }

        function renderConfigurations() {
            const container = document.getElementById('configurations');
            
            if (configurations.length === 0) {
                container.innerHTML = `
                    <div class="empty-state">
                        <h3>暂无配置</h3>
                        <p>点击下方按钮添加您的虚拟机配置</p>
                    </div>
                `;
                return;
            }
            
            container.innerHTML = configurations.map(config => {
                const adjustedSystemDisk = getAdjustedDiskSize(config.systemDiskPerVM, config.systemDiskType, 'system');
                
                // 计算数据盘汇总
                const dataDiskSummary = config.dataDisks.reduce((acc, disk) => {
                    const adjustedSize = getAdjustedDiskSize(disk.size, disk.type, 'data');
                    const totalSize = adjustedSize * config.vmCount;
                    
                    if (!acc[disk.type]) {
                        acc[disk.type] = 0;
                    }
                    acc[disk.type] += totalSize;
                    return acc;
                }, {});
                
                return `
                    <div class="config-item">
                        <h3>
                            <input type="text" value="${config.name}" 
                                   onchange="updateConfigName(${config.id}, this.value)"
                                   style="background:rgba(255,255,255,0.3); border:none; color:white; padding:5px; border-radius:5px; width:150px;">
                            <div>
                                <span>${config.vmCount}台虚机</span>
                                <button class="delete-btn" onclick="removeConfiguration(${config.id})">删除</button>
                            </div>
                        </h3>
                        <div class="config-controls">
                            <button onclick="changeVMCount(${config.id}, -1)">-</button>
                            <input type="number" value="${config.vmCount}" min="1" 
                                   onchange="updateConfiguration(${config.id}, 'vmCount', this.value)">
                            <button onclick="changeVMCount(${config.id}, 1)">+</button>
                            <span>台虚机</span>
                        </div>
                        <div class="spec-grid">
                            <div class="spec-item">
                                <label>CPU核心</label>
                                <input type="number" value="${config.cpuPerVM}" min="1"
                                       onchange="updateConfiguration(${config.id}, 'cpuPerVM', this.value)">
                            </div>
                            <div class="spec-item">
                                <label>内存(G)</label>
                                <input type="number" value="${config.memoryPerVM}" min="1"
                                       onchange="updateConfiguration(${config.id}, 'memoryPerVM', this.value)">
                            </div>
                        </div>
                        
                        <div class="disk-config">
                            <div class="disk-title">💾 系统盘配置</div>
                            <div class="disk-row">
                                <div class="spec-item">
                                    <label>容量(G)</label>
                                    <input type="number" value="${config.systemDiskPerVM}" min="1"
                                           onchange="updateConfiguration(${config.id}, 'systemDiskPerVM', this.value)">
                                    ${DISK_TYPES.system[config.systemDiskType].needsAdjust && config.systemDiskPerVM !== adjustedSystemDisk ? 
                                        `<div class="auto-adjust">自动调整为 ${adjustedSystemDisk}G</div>` : ''}
                                </div>
                                <div class="spec-item">
                                    <label>磁盘类型</label>
                                    <select onchange="updateConfiguration(${config.id}, 'systemDiskType', this.value)">
                                        ${Object.entries(DISK_TYPES.system).map(([key, info]) => 
                                            `<option value="${key}" ${config.systemDiskType === key ? 'selected' : ''}>${info.name}</option>`
                                        ).join('')}
                                    </select>
                                </div>
                                <div class="spec-item">
                                    <label>实际总容量</label>
                                    <input type="text" value="${adjustedSystemDisk * config.vmCount}G" readonly 
                                           style="background: #f0f0f0; color: #666;">
                                </div>
                            </div>
                        </div>

                        <div class="disk-config">
                            <div class="disk-title">
                                💿 数据盘配置 (${config.dataDisks.length}块)
                                <button class="add-disk-btn" onclick="addDataDisk(${config.id})">➕ 添加数据盘</button>
                            </div>
                            <div class="data-disks-container">
                                ${config.dataDisks.length > 0 ? config.dataDisks.map((disk, index) => {
                                    const adjustedSize = getAdjustedDiskSize(disk.size, disk.type, 'data');
                                    return `
                                        <div class="data-disk-item">
                                            <div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;">
                                                <span style="font-weight: bold; font-size: 0.85em;">数据盘 ${index + 1}</span>
                                                <button class="remove-disk-btn" onclick="removeDataDisk(${config.id}, ${disk.id})">删除</button>
                                            </div>
                                            <div class="disk-row">
                                                <div class="spec-item">
                                                    <label>容量(G)</label>
                                                    <input type="number" value="${disk.size}" min="1"
                                                           onchange="updateDataDisk(${config.id}, ${disk.id}, 'size', this.value)">
                                                    ${DISK_TYPES.data[disk.type].needsAdjust && disk.size !== adjustedSize ? 
                                                        `<div class="auto-adjust">调整为 ${adjustedSize}G</div>` : ''}
                                                </div>
                                                <div class="spec-item">
                                                    <label>磁盘类型</label>
                                                    <select onchange="updateDataDisk(${config.id}, ${disk.id}, 'type', this.value)">
                                                        ${Object.entries(DISK_TYPES.data).map(([key, info]) => 
                                                            `<option value="${key}" ${disk.type === key ? 'selected' : ''}>${info.name}</option>`
                                                        ).join('')}
                                                    </select>
                                                </div>
                                                <div class="spec-item">
                                                    <label>单盘总容量</label>
                                                    <input type="text" value="${formatDiskSize(adjustedSize * config.vmCount)}" readonly 
                                                           style="background: #f0f0f0; color: #666;">
                                                </div>
                                            </div>
                                        </div>
                                    `;
                                }).join('') : '<div style="text-align: center; padding: 20px; color: rgba(255,255,255,0.7); font-size: 0.9em;">暂无数据盘配置</div>'}
                            </div>
                            
                            ${config.dataDisks.length > 0 ? `
                            <div class="disk-summary">
                                <div style="font-weight: bold; margin-bottom: 5px; text-align: center;">数据盘总计</div>
                                ${Object.entries(dataDiskSummary).map(([type, total]) => 
                                    `<div class="disk-summary-row">
                                        <span>${DISK_TYPES.data[type].name}:</span>
                                        <span>${formatDiskSize(total)}</span>
                                    </div>`
                                ).join('')}
                            </div>` : ''}
                        </div>

                        <div class="spec-grid">
                            <div class="spec-item">
                                <label>带宽(M)</label>
                                <input type="number" value="${config.bandwidth}" min="1"
                                       onchange="updateConfiguration(${config.id}, 'bandwidth', this.value)">
                            </div>
                        </div>
                    </div>
                `;
            }).join('');
            
            renderGroupResults();
        }

        function updateConfigName(id, name) {
            const config = configurations.find(c => c.id === id);
            if (config) {
                config.name = name;
            }
        }

        function renderGroupResults() {
            const container = document.getElementById('groupResults');
            
            if (configurations.length === 0) {
                container.innerHTML = `
                    <div class="empty-state">
                        <h3>暂无统计数据</h3>
                        <p>添加配置后这里会显示详细统计</p>
                    </div>
                `;
                return;
            }
            
            container.innerHTML = configurations.map(config => {
                const totalCPU = config.vmCount * config.cpuPerVM;
                const totalMemory = config.vmCount * config.memoryPerVM;
                const adjustedSystemDisk = getAdjustedDiskSize(config.systemDiskPerVM, config.systemDiskType, 'system');
                const totalSystemDisk = config.vmCount * adjustedSystemDisk;
                
                // 计算所有数据盘的总容量
                const totalDataDisksByType = config.dataDisks.reduce((acc, disk) => {
                    const adjustedSize = getAdjustedDiskSize(disk.size, disk.type, 'data');
                    const totalSize = adjustedSize * config.vmCount;
                    
                    if (!acc[disk.type]) {
                        acc[disk.type] = 0;
                    }
                    acc[disk.type] += totalSize;
                    return acc;
                }, {});
                
                const totalAllDataDisks = Object.values(totalDataDisksByType).reduce((sum, size) => sum + size, 0);
                
                return `
                    <div class="result-item">
                        <h3>${config.name}</h3>
                        <div class="result-stats">
                            <div class="stat-box">
                                <div class="stat-label">虚机数量</div>
                                <div class="stat-value">${config.vmCount}</div>
                            </div>
                            <div class="stat-box">
                                <div class="stat-label">CPU核心</div>
                                <div class="stat-value">${totalCPU}</div>
                            </div>
                            <div class="stat-box">
                                <div class="stat-label">内存</div>
                                <div class="stat-value">${totalMemory}G</div>
                            </div>
                            <div class="stat-box">
                                <div class="stat-label">系统盘</div>
                                <div class="stat-value">${totalSystemDisk}G</div>
                            </div>
                            <div class="stat-box">
                                <div class="stat-label">数据盘数量</div>
                                <div class="stat-value">${config.dataDisks.length}块</div>
                            </div>
                            <div class="stat-box">
                                <div class="stat-label">数据盘总量</div>
                                <div class="stat-value">${formatDiskSize(totalAllDataDisks)}</div>
                            </div>
                            <div class="stat-box">
                                <div class="stat-label">校园网IP</div>
                                <div class="stat-value">${config.vmCount}</div>
                            </div>
                            <div class="stat-box">
                                <div class="stat-label">带宽</div>
                                <div class="stat-value">${config.bandwidth}M</div>
                            </div>
                        </div>
                        <div class="disk-type-stats">
                            <div style="font-weight: bold; margin-bottom: 5px; text-align: center;">磁盘类型分布</div>
                            <div class="disk-stats-grid">
                                <div class="disk-stat-item">
                                    <div class="disk-stat-label">系统盘</div>
                                    <div class="disk-stat-value">${DISK_TYPES.system[config.systemDiskType].name}</div>
                                </div>
                                ${Object.keys(totalDataDisksByType).length > 0 ? 
                                    Object.entries(totalDataDisksByType).map(([type, total]) => 
                                        `<div class="disk-stat-item">
                                            <div class="disk-stat-label">${DISK_TYPES.data[type].name}</div>
                                            <div class="disk-stat-value">${formatDiskSize(total)}</div>
                                        </div>`
                                    ).join('') :
                                    `<div class="disk-stat-item">
                                        <div class="disk-stat-label">数据盘</div>
                                        <div class="disk-stat-value">无</div>
                                    </div>`
                                }
                            </div>
                        </div>
                    </div>
                `;
            }).join('');
        }

        function calculateTotals() {
            const totals = configurations.reduce((acc, config) => {
                const adjustedSystemDisk = getAdjustedDiskSize(config.systemDiskPerVM, config.systemDiskType, 'system');
                
                acc.vms += config.vmCount;
                acc.cpu += config.vmCount * config.cpuPerVM;
                acc.memory += config.vmCount * config.memoryPerVM;
                acc.ips += config.vmCount;
                acc.bandwidth += config.vmCount * config.bandwidth; // 计算总带宽
                
                // 按类型统计系统盘
                const systemDiskTotal = config.vmCount * adjustedSystemDisk;
                if (config.systemDiskType === 'dell') {
                    acc.systemDiskDell += systemDiskTotal;
                } else if (config.systemDiskType === 'ssd') {
                    acc.systemDiskSSD += systemDiskTotal;
                }
                
                // 按类型统计数据盘
                config.dataDisks.forEach(disk => {
                    const adjustedSize = getAdjustedDiskSize(disk.size, disk.type, 'data');
                    const totalSize = adjustedSize * config.vmCount;
                    
                    if (disk.type === 'dell') {
                        acc.dataDiskDell += totalSize;
                    } else if (disk.type === 'shuguang') {
                        acc.dataDiskShuguang += totalSize;
                    } else if (disk.type === 'ssd') {
                        acc.dataDiskSSD += totalSize;
                    }
                });
                
                return acc;
            }, { 
                vms: 0, cpu: 0, memory: 0, ips: 0, bandwidth: 0,
                systemDiskDell: 0, systemDiskSSD: 0,
                dataDiskDell: 0, dataDiskShuguang: 0, dataDiskSSD: 0
            });

            document.getElementById('totalVMs').textContent = totals.vms;
            document.getElementById('totalCPU').textContent = totals.cpu;
            document.getElementById('totalMemory').textContent = totals.memory + 'G';
            document.getElementById('totalSystemDiskDell').textContent = totals.systemDiskDell + 'G';
            document.getElementById('totalSystemDiskSSD').textContent = totals.systemDiskSSD + 'G';
            document.getElementById('totalDataDiskDell').textContent = formatDiskSize(totals.dataDiskDell);
            document.getElementById('totalDataDiskShuguang').textContent = formatDiskSize(totals.dataDiskShuguang);
            document.getElementById('totalDataDiskSSD').textContent = formatDiskSize(totals.dataDiskSSD);
            document.getElementById('totalIPs').textContent = totals.ips;
            document.getElementById('totalBandwidth').textContent = totals.bandwidth + 'M';
        }

        function formatDiskSize(sizeInGB) {
            return sizeInGB + 'G';
        }

        // 页面加载时初始化 - 不添加任何默认配置
        window.onload = function() {
            renderConfigurations();
            calculateTotals();
        };
    </script>
</body>
</html>